package jiemian1;

import user.Member;
import user.MemberManager;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;

public class Set {
    private JComboBox select;
    private JTextField sureanswertxt;
    private JTextField answertxt;
    private JComboBox selectproblem;
    private JTextField answertxt2;
    private JTextField sureanswertxt2;
    private JLabel problem;
    private JLabel answer;
    private JLabel sureanswer;
    private JLabel problem2;
    private JLabel answer2;
    private JLabel sureanswer2;
    public JPanel set;
    private JButton deletebtn;
    private JButton surebtn;
    private String id;
    private String password;
    private static String answ1;
    private static String answ2;
    public static JFrame frame = new JFrame("Set");

    public Set() {
        surebtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //关闭页面并且更新数据库
                   frame.dispose();
            }
        });

        deletebtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
            }
        });
    }
    public Set(JFrame y) {
        frame=y;
        surebtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //点击确认按钮后更新数据库
                // 之后关闭页面
                frame.dispose();
            }
        });

        deletebtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
            }
        });
    }

    public Set(JFrame y,String i,String p) {
        frame=y;
        id=i;
        password=p;
        surebtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //点击确认按钮后更新数据库
                System.out.println("53653652");
                Member bean=new Member();
                answ1=answertxt.getText();
                answ2=answertxt2.getText();
                bean.setUserId(id);
                bean.setPasswd(p);
                bean.setAnswer1(answ1);
                bean.setAnswer2(answ2);

                System.out.println(bean.toString());

                try {
                    MemberManager.registerUser(bean);
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
                // 之后关闭页面
                frame.dispose();
            }
        });

        deletebtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
            }
        });
    }

    public static void main(String[] args) {

        frame.setContentPane(new Set().set);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(((Toolkit.getDefaultToolkit().getScreenSize().width)/2)-300,
                ((Toolkit.getDefaultToolkit().getScreenSize().height)/2)-300,600,600);
        frame.pack();
        frame.setVisible(true);
        frame.setSize(400,300);
    }
}
